import 'package:flutter_admin/utils/utils.dart';
import 'package:quiver/strings.dart';

class StockMaterialcheck {
  String? id;
  String? name;
  String? warehouseId;
  String? warehouseName;
  String? remark;
  String? createUid;
  String? createName;
  String? createDate;
  String? createDateStart;
  String? createDateEnd;
  String? writeUid;
  String? writeDate;
  String? inventoryId; //盘点人
  String? inventoryName; //盘点人
  String? inventoryTime; //盘点时间
  String? isCheck; //是否盘点
  String? isOver; //是否平库


  StockMaterialcheck({
    this.id,
    this.name,
    this.warehouseId,
    this.warehouseName,
    this.remark,
    this.createUid,
    this.createName,
    this.createDate,
    this.createDateStart,
    this.createDateEnd,
    this.writeUid,
    this.writeDate,
    this.inventoryId,
    this.inventoryName,
    this.inventoryTime,
    this.isCheck,
    this.isOver,
  });

  StockMaterialcheck copyWith({
    String? id,
    String? name,
    String? warehouseId,
    String? remark,
    String? createUid,
    String? createDate,
    String? writeUid,
    String? writeDate,
  }) {
    return new StockMaterialcheck(
      id: id ?? this.id,
      name: name ?? this.name,
      warehouseId: warehouseId ?? this.warehouseId,
      remark: remark ?? this.remark,
      createUid: createUid ?? this.createUid,
      createDate: createDate ?? this.createDate,
      writeUid: writeUid ?? this.writeUid,
      writeDate: writeDate ?? this.writeDate,
    );
  }

  @override
  String toString() {
    return '''StockMaterialcheck{
      id: id,
      name: name,
      warehouseId: warehouseId,
      remark: remark,
      createUid: createUid,
      createDate: createDate,
      writeUid: writeUid,
      writeDate: writeDate,
    }''';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      (other is StockMaterialcheck &&
          runtimeType == other.runtimeType &&
          id == other.id &&
          name == other.name &&
          warehouseId == other.warehouseId &&
          remark == other.remark &&
          createUid == other.createUid &&
          createDate == other.createDate &&
          writeUid == other.writeUid &&
          writeDate == other.writeDate);

  factory StockMaterialcheck.fromMap(Map<String, dynamic> map) {
    return new StockMaterialcheck(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      name: map['name'] != false
          ? map['name'].toString() as String?
          : "",
      warehouseId: map['warehouse_id'] != false
          ? map['warehouse_id'][0].toString() as String?
          : "",
      warehouseName: map['warehouse_id'] != false
          ? map['warehouse_id'][1].toString() as String?
          : "",
      remark: map['remark'] != false ? map['remark'].toString() as String? : "",
      createUid: map['create_uid'] != false
          ? map['create_uid'][0].toString() as String?
          : "",
      createName: map['create_uid'] != false
          ? map['create_uid'][1].toString() as String?
          : "",
      createDate: map['create_date'] != false
          ? map['create_date'].toString() as String?
          : "",
      writeUid: map['write_uid'] != false
          ? map['write_uid'].toString() as String?
          : "",
      writeDate: map['write_date'] != false
          ? map['write_date'].toString() as String?
          : "",
      inventoryId: map['inventory_id'] != false
          ? map['inventory_id'][0].toString() as String?
          : null,
      inventoryName: map['inventory_id'] != false
          ? map['inventory_id'][1].toString() as String?
          : "",
      inventoryTime: map['inventory_time'] != false
          ? map['inventory_time'].toString() as String?
          : null,
      isCheck: map['is_check'] != false
          ? map['is_check'].toString() as String?
          : '',
      isOver: map['is_over'] != false
          ? map['is_over'].toString() as String?
          : '',

    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'name': this.name,
      'warehouseId': this.warehouseId,
      'remark': this.remark,
      'createUid': this.createUid,
      'createDate': this.createDate,
      'writeUid': this.writeUid,
      'writeDate': this.writeDate,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    List list = [
      if (this.warehouseId != null && this.warehouseId != '')
        ['warehouse_id', '=', int.parse(this.warehouseId!)],
      if (this.createDateStart != null && this.createDateStart != '')
        [
          'create_date',
          '>=',
          Utils.timeUTC(this.createDateStart! + ' 00:00:00', isToBeijing: false)
        ],
      if (this.createDateEnd != null && this.createDateEnd != '')
        [
          'create_date',
          '<=',
          Utils.timeUTC(this.createDateEnd! + ' 23:59:59', isToBeijing: false)
        ],
    ];
    if (list.length == 0) {
      list.add(['id', '!=', null]);
    }
    // ignore: unnecessary_cast
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'name': this.name,
      'warehouse_id': int.parse(this.warehouseId!),
      'remark': this.remark,
      'inventory_id': isBlank(this.inventoryId)?null:int.parse(this.inventoryId!),
      'inventory_time': this.inventoryTime,
    } as Map<String, dynamic>;
  }

//</editor-fold>

}
